//
//  WeiboViewController.m
//  微博
//
//  Created by song on 15/1/13.
//  Copyright (c) 2015年 song. All rights reserved.
//

#import "WeiboViewController.h"
#import "JOStatus.h"
#import  "JOStatuseCell.h"
#import "JOStatuseFrame.h"
@interface WeiboViewController ()

@end

@implementation WeiboViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.tableView.rowHeight = 400;
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


-(NSArray *)statuses
{
    if(_statuses ==nil)
    {
        NSArray *datas = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"statuses.plist" ofType:nil]];
        NSMutableArray *marray =[NSMutableArray array];
        
        for(NSDictionary *dict in datas)
        {
            JOStatus *status =[JOStatus weiboWithDict:dict];
            JOStatuseFrame *statusFrame = [[JOStatuseFrame alloc]init];
            statusFrame.status = status;
            [marray addObject:statusFrame];
        }
        _statuses = marray;
    }

    return _statuses;
    
}



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.statuses.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    JOStatuseCell *cell = [tableView dequeueReusableCellWithIdentifier:@"A"];
    if(cell ==nil)
    {
        cell = [[JOStatuseCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"A"];
    }
    
    cell.statusFrame = self.statuses[indexPath.row];
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    JOStatuseFrame *frame = self.statuses[indexPath.row];
    return frame.cellHeight;
}

@end
